// 快手视频数据服务
export const mockKuaishouData = {
  // 视频列表数据
  videos: [
    {
      id: 'XaAtP7gRjISiTYy',  // 使用实际的快手视频ID
      title: '快手舞蹈视频合集',
      cover: '/ks.png',
      videoUrl: 'https://www.kuaishou.com/f/XaAtP7gRjISiTYy',
      embedUrl: 'https://www.kuaishou.com/f/X5jF8rEi20lb2d4', // 添加嵌入式URL
      author: {
        id: '3x4q9vp8k2m7n1',
        name: '快手舞蹈达人',
        avatar: '/src/assets/images/avatar/1.jpg',
        verified: true,
      },
      stats: {
        views: '268.5万',
        likes: '12.3万',
        comments: '2089',
        shares: '1.2万',
        collects: '3.4万',
      },
      tags: ['舞蹈', '音乐', '快手'],
      description: '精选快手舞蹈视频，欢迎关注！',
      duration: '0:58',
      publishTime: '2024-03-20 15:30:00',
      status: 'normal',
    },
    {
      id: 'X6ZbLwiNULOHB4f',
      title: '快手美食探店',
      cover: '/src/assets/images/video/2.jpg',
      videoUrl: 'https://www.kuaishou.com/f/X6ZbLwiNULOHB4f',
      embedUrl: 'https://www.kuaishou.com/f/X-COLGv7OdOHMSr',
      author: {
        id: '3x7m2np9k4v6q8',
        name: '美食达人',
        avatar: '/src/assets/images/avatar/2.jpg',
        verified: true,
      },
      stats: {
        views: '156.8万',
        likes: '8.9万',
        comments: '1567',
        shares: '8900',
        collects: '2.3万',
      },
      tags: ['美食', '探店', '生活'],
      description: '带你探索各地美食，寻找舌尖上的美味！',
      duration: '5:24',
      publishTime: '2024-03-20 14:20:00',
      status: 'normal',
    },
  ],

  // 获取视频列表
  getVideoList() {
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          list: this.videos,
          total: this.videos.length,
        })
      }, 300)
    })
  },

  // 获取视频详情
  getVideoDetail(id) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        const video = this.videos.find((v) => v.id === id)
        if (video) {
          resolve(video)
        } else {
          reject(new Error('视频不存在'))
        }
      }, 200)
    })
  },

  // 获取视频统计数据
  getVideoStats(id) {
    return new Promise((resolve) => {
      setTimeout(() => {
        const video = this.videos.find((v) => v.id === id)
        if (video) {
          // 模拟实时数据变化
          const randomIncrease = (num) => {
            const base = parseInt(num.replace(/[^\d]/g, ''))
            return base + Math.floor(Math.random() * 100)
          }

          resolve({
            ...video.stats,
            views: randomIncrease(video.stats.views),
            likes: randomIncrease(video.stats.likes),
            comments: randomIncrease(video.stats.comments),
          })
        }
      }, 200)
    })
  },

  // 获取相关视频
  getRelatedVideos(id, limit = 5) {
    return new Promise((resolve) => {
      setTimeout(() => {
        const currentVideo = this.videos.find((v) => v.id === id)
        const relatedVideos = this.videos
          .filter(
            (v) =>
              v.id !== id &&
              v.tags.some((tag) => currentVideo.tags.includes(tag)),
          )
          .slice(0, limit)
        resolve(relatedVideos)
      }, 400)
    })
  },

  // 构建快手播放器URL
  getVideoUrl(video) {
    return video.embedUrl || `https://www.kuaishou.com/short-video/${video.id}`
  },

  // 模拟视频播放进度
  getVideoProgress(id) {
    return new Promise((resolve) => {
      const progress = localStorage.getItem(`ks-video-progress-${id}`) || '0'
      resolve(parseInt(progress))
    })
  },

  // 保存视频播放进度
  saveVideoProgress(id, progress) {
    return new Promise((resolve) => {
      localStorage.setItem(`ks-video-progress-${id}`, progress.toString())
      resolve(true)
    })
  },
}
